import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/Servlet1")
public class Servlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //getMethod() 获取请求方式
        String method = req.getMethod();
        System.out.println("Method: " + method);
        //getContextPath() 获取web应用名称
        String contextPath = req.getContextPath();
        System.out.println("ContextPath: " + contextPath);
        //getRequestURI() 获取请求地址,不带主机名
        String requestURI = req.getRequestURI();
        System.out.println("RequestURI: " + requestURI);
        //getRequestURL() 获取请求地址,带主机名
        StringBuffer requestURL = req.getRequestURL();
        System.out.println("RequestURI1: " + requestURL);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      doGet(req,resp);
    }
}
